package com.ruoyi.web.controller.comment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comment.domain.ResInformationComment;
import com.ruoyi.comment.service.IResInformationCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资讯评论Controller
 * 
 * @author ruoyi
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/comment/information")
public class ResInformationCommentController extends BaseController
{
    @Autowired
    private IResInformationCommentService resInformationCommentService;

    /**
     * 查询资讯评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResInformationComment resInformationComment)
    {
        startPage();
        List<ResInformationComment> list = resInformationCommentService.selectResInformationCommentList(resInformationComment);
        return getDataTable(list);
    }

    /**
     * 用户查询资讯评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:information:userViewList')")
    @GetMapping("/userViewList")
    public TableDataInfo userViewList(ResInformationComment resInformationComment)
    {
        List<ResInformationComment> list = resInformationCommentService.selectResInformationCommentTreeList(resInformationComment);
        return getDataTable(list);
    }
    /**
     * 导出资讯评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:information:export')")
    @Log(title = "资讯评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResInformationComment resInformationComment)
    {
        List<ResInformationComment> list = resInformationCommentService.selectResInformationCommentList(resInformationComment);
        ExcelUtil<ResInformationComment> util = new ExcelUtil<ResInformationComment>(ResInformationComment.class);
        util.exportExcel(response, list, "资讯评论数据");
    }

    /**
     * 获取资讯评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:information:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(resInformationCommentService.selectResInformationCommentById(id));
    }

    /**
     * 新增资讯评论
     */
    @PreAuthorize("@ss.hasPermi('comment:information:add')")
    @Log(title = "资讯评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResInformationComment resInformationComment)
    {
        resInformationComment.setUserId(getUserId());
        resInformationComment.setCreateBy(getUsername());
        if(resInformationCommentService.insertResInformationComment(resInformationComment)==1){
            return toAjax(resInformationCommentService.updateResInformationComment(resInformationComment));
        }else{
            return toAjax(0);
        }
    }

    /**
     * 修改资讯评论
     */
    @PreAuthorize("@ss.hasPermi('comment:information:edit')")
    @Log(title = "资讯评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResInformationComment resInformationComment)
    {
        return toAjax(resInformationCommentService.updateResInformationComment(resInformationComment));
    }

    /**
     * 删除资讯评论
     */
    @PreAuthorize("@ss.hasPermi('comment:information:remove')")
    @Log(title = "资讯评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resInformationCommentService.deleteResInformationCommentByIds(ids));
    }
}
